﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_winformInfo
    {
        private int _formid;
        private string _tenform;
        private string _ghichu;

        public cs_hmr_winformInfo(int formid, string tenform, string ghichu)
        {
            this._formid = formid;
            this._tenform = tenform;
            this._ghichu = ghichu;

        }
        public cs_hmr_winformInfo()
        {
            this._formid = 0;
            this._tenform = " ";
            this._ghichu = " ";

        }
        public int formid
        {
            get
            {
                return this._formid;
            }
            set
            {
                this._formid = value;
            }
        }
        public string tenform
        {
            get
            {
                return this._tenform;
            }
            set
            {
                this._tenform = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[4];
            paraName[0] = "@formid";
            paraName[1] = "@tenform";
            paraName[2] = "@ghichu";
            paraName[3] = "@option";
            object[] paraValue = new object[4];
            paraValue[0] = this._formid;
            paraValue[1] = this._tenform;
            paraValue[2] = this._ghichu;
            paraValue[3] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 4, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[3];
            fields[0] = "formid";
            fields[1] = "tenform";
            fields[2] = "ghichu";
            list.KetDulieu(myList, "HMR_WINFORM", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_WINFORM", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("tenform", "formid");
            cb.KetDuLieu(cbo, "HMR_WINFORM", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[3];
            header[0] = "formid";
            header[1] = "tenform";
            header[2] = "ghichu";

            string[] mappingname = new string[3];
            mappingname[0] = "formid";
            mappingname[1] = "tenform";
            mappingname[2] = "ghichu";

            int[] colwidth = new int[3];
            colwidth[0] = 12;
            colwidth[1] = 300;
            colwidth[2] = 1200;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_WINFORM", datagrid, csdl.OpenTable("HMR_WINFORM", condition), header, mappingname, colwidth, 3);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_WINFORM", "tenform = '" + this._tenform + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._formid = Convert.ToInt32(ds.Tables[0].Rows[0]["formid"].ToString().Trim());
                this._tenform = ds.Tables[0].Rows[0]["tenform"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select formid, tenform, ghichu"
                        + " from hmr_winform"
                        + " order by tenform asc";
                ds = csdl.SelecSQL(sql);
                
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
